package polymorphicdemo;

public abstract class Animal {
    int age;
    String color;

    public Animal() {
    }

    public Animal(int age, String color) {
        this.age = age;
        this.color = color;
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    /**
     * 获取
     * @return color
     */
    public String getColor() {
        return color;
    }

    /**
     * 设置
     * @param color
     */
    public void setColor(String color) {
        this.color = color;
    }

    public String toString() {
        return "Animel{age = " + age + ", color = " + color + "}";
    }

    public void eat(Animal a,String food){
        //System.out.println(getAge()+"岁的"+getColor()+"的"+getSpecies()+"在吃"+food);
        String wuzhong = a instanceof Dog ? "狗" : "猫";
        System.out.println(getAge()+"岁的"+getColor()+"颜色的"+ wuzhong+"在吃"+food);
    }
}
